package com.magic.interview.模拟.LC884两句话中不常见的单词;

import java.util.*;

/**
 * @author laoma
 * @create 2022-01-30 10:59
 */
public class Solution {
    public String[] uncommonFromSentences(String s1, String s2) {
        String[] ss1 = s1.split(" ");
        String[] ss2 = s2.split(" ");
        List<String> ansList = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        for (String s : ss1) {
            map.put(s, map.getOrDefault(s, 0) + 1);
        }
        for (String s : ss2) {
            map.put(s, map.getOrDefault(s, 0) + 1);
        }
        for (String s : map.keySet()) {
            if(map.get(s) == 1){
                ansList.add(s);
            }
        }
        return ansList.toArray(new String[ansList.size()]);
    }
}
